<%-- 
    Document   : loginDetails
    Created on : Mar 22, 2013, 11:05:49 AM
    Author     : Andrew Severson
--%>
<%! private String url = "jdbc:mysql://webdev.cs.uwosh.edu:4381/" ;%>
<%! private String db = "severa24"; %>
<%! private String uid = "severa24" ;%>
<%! private String pwd = "d450224"; %>
<%@ page import="java.math.BigInteger" %>
<%@ page import="java.security.MessageDigest" %>
<%@ page import="java.security.NoSuchAlgorithmException" %>
<%@ page import="java.util.UUID" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %>
<%! 
//this method will generate a hashed String for the given input string
public static String md5(String input) 
{
    String md5 = null;

    if(null == input) return null;

    try 
    {
        //Create MessageDigest object for MD5
        MessageDigest digest = MessageDigest.getInstance("MD5");

        //Update input string in message digest
        digest.update(input.getBytes(), 0, input.length());

        //Converts message digest value in base 16 (hex) 
        md5 = new BigInteger(1, digest.digest()).toString(16);
    } 
    catch (NoSuchAlgorithmException e) 
    {
        e.printStackTrace();
    }
    return md5;
}

public static String getSalt(){
    return UUID.randomUUID().toString();
}

/*
 * this check to see if the input password is the same is the one stored in the database
 * ARGUMENTS: the database password, database salt, and the user input password
 * RETURNED: A boolean indicated if it is a match or not
 */
public static boolean CheckPasswordCorrect(String dbPassword, String dbSalt, String inputPassword)
{
    if(dbPassword.equalsIgnoreCase( md5(inputPassword + dbSalt)))
    {
            return true;
    }
    return false;
}
%>